<template>
    <view class="page">
        <view class="sxlb">
            <view @tap="chosetype" class="sxlbv" :style="'color:' + (selecttype ? color : '') + ';border-bottom:' + (selecttype ? 2 : '0') + 'rpx solid ' + color">
                <view>{{ typename }}</view>
                <image :class="selecttype ? 'xs' : 'xx'" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/down1.png"></image>
            </view>
            <view @tap="choseinfo" class="sxlbv" :style="'color:' + (selectinfo ? color : '') + ';border-bottom:' + (selectinfo ? 2 : '0') + 'rpx solid ' + color">
                <view>关键词查找</view>
                <image :class="selectinfo ? 'xs' : 'xx'" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/down1.png"></image>
            </view>
            <view :class="'sorting-list ' + (!selecttype ? ' chioce-list-hide' : ' chioce-list-show')">
                <view @tap="xztype" class="sorting-item" :data-index="index" v-for="(item, index) in datetype" :key="index">{{ item }}</view>
            </view>
            <view :class="'sorting-list ' + (!selectinfo ? ' chioce-list-hide' : ' chioce-list-show')">
                <view class="weui-cell weui-cell_input" style="padding: 10rpx 30rpx">
                    <view class="weui-cell__bd">
                        <input @input="qginfoinput" class="weui-input" placeholder="请输入姓名/订单编号" :value="searchinfo" />
                    </view>
                </view>
                <view class="datebtn">
                    <button @tap.stop.prevent="search" :data-id="oitem.id" :style="'background:' + color + ';color: #fff;'">查找</button>
                </view>
            </view>
        </view>
        <view @tap="hidemask" class="mask" v-if="!(!selecttype && !selectdate && !selectinfo)"></view>
        <view class="main">
            <view class="no-data-tip zwdd" v-if="order_list.length == 0 && mygd">
                <image mode="aspectFit" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/list.png"></image>
                <view>您暂无相关订单哦~</view>
            </view>
            <navigator
                class="weui-cells weui-cells_after-title"
                hoverClass="none"
                :style="'filter: ' + (oitem.state == 3 ? 'grayscale(100%)' : '') + ';background:' + (oitem.state == 3 ? '#EDEDED' : '')"
                v-for="(oitem, oindex) in order_list"
                :key="oindex"
            >
                <view class="weui-cell">
                    <view class="weui-cell__hd ddxh" :style="'color:' + color">#{{ oitem.id }}</view>
                    <view class="weui-cell__bd">截止日期：{{ oitem.xf_time }}</view>
                    <view class="weui-cell__ft" :style="'color:' + color" v-if="oitem.state == '1'">待付款</view>
                    <view class="weui-cell__ft" :style="'color:' + color" v-if="oitem.state == '2'">已付款</view>
                    <view class="weui-cell__ft" :style="'color:' + color" v-if="oitem.state == '3'">已完成</view>
                    <view class="weui-cell__ft" :style="'color:' + color" v-if="oitem.state == '4'">已关闭</view>
                    <view class="weui-cell__ft" :style="'color:' + color" v-if="oitem.state == '5'">已失效</view>
                </view>

                <view class="weui-cell">
                    <view class="weui-cell__bd">{{ oitem.nick_name }}</view>
                    <view class="weui-cell__ft bold" style="color: #66cd00" v-if="oitem.pay_type == '1'">微信支付</view>
                    <view class="weui-cell__ft bold" style="color: #eead0e" v-if="oitem.pay_type == '2'">余额支付</view>
                    <view class="weui-cell__ft bold" style="color: #ff6347" v-if="oitem.pay_type == '5'">餐后支付</view>
                </view>

                <view @tap.stop.prevent="kindToggle" class="weui-cell" :id="oindex">
                    <view class="weui-cell__hd">商品信息：</view>
                    <view class="weui-cell__bd" style="color: #999; font-size: 22rpx">{{ oitem.goods_name }}</view>
                    <view class="weui-cell__ft">
                        <image :class="oitem.open ? 'xs' : 'xx'" mode="aspectFit" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/down1.png"></image>
                    </view>
                </view>

                <view class="weui-cell" v-if="oitem.open">
                    <view class="weui-cell__hd">
                        <image :src="oitem.logo"></image>
                    </view>
                    <view class="weui-cell__bd">{{ oitem.goods_name }}</view>
                    <view class="weui-cell__ft cpjg">
                        <text>x{{ oitem.goods_num }}</text>
                        ￥{{ oitem.money }}
                    </view>
                </view>

                <view @tap.stop.prevent="maketel" class="weui-cell" :data-tel="oitem.receive_tel">
                    <view class="weui-cell__hd">客户已支付：</view>
                    <view class="weui-cell__bd" :style="'color:' + color">{{ oitem.price }}元</view>
                    <view class="weui-cell__ft">
                        <image mode="aspectFit" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/lxsj.png"></image>
                    </view>
                </view>

                <view class="ddxx">
                    <view>订单编号：{{ oitem.order_num }}</view>
                    <view>下单时间：{{ oitem.time }}</view>
                    <view v-if="oitem.note != ''">留言备注：{{ oitem.note }}</view>
                </view>
            </navigator>
            <view class="jzz" v-if="!mygd">
                <image class="Rotation" src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/jzz.png"></image>
                <view>加载中...</view>
            </view>
            <view class="jzwb" v-if="mygd">
                <view class="hx"></view>
                <view class="wz">加载完毕</view>
                <view class="hx"></view>
            </view>
        </view>
    </view>
</template>

<script>
var app = getApp();
var util = require('../../../utils/util.js');
export default {
    data() {
        return {
            selectedindex: 0,

            topnav: [
                {
                    img: '../static/icon/dzt.png',
                    img1: '../static/icon/wdzt.png',
                    name: '全部'
                },
                {
                    img: '../static/icon/djd.png',
                    img1: '../static/icon/wdjd.png',
                    name: '待支付'
                },
                {
                    img: '../static/icon/ywc.png',
                    img1: '../static/icon/wywc.png',
                    name: '已完成'
                },
                {
                    img: '../static/icon/sh.png',
                    img1: '../static/icon/wsh.png',
                    name: '已关闭'
                }
            ],

            open: false,
            pagenum: 1,
            order_list: [],
            storelist: [],
            mygd: false,
            jzgd: true,
            selecttype: false,
            typename: '选择类型',
            selectdate: false,
            datetype: ['全部', '未付款', '已付款', '已完成', '已关闭', '已失效'],
            start: '',
            timestart: '',
            timeend: '',
            start_time: '',
            end_time: '',
            xtxx: '',
            selectinfo: '',
            searchinfo: '',
            state: '',
            status: 0,
            time: '',
            color: '',

            oitem: {
                id: '',
                state: 0,
                xf_time: '',
                nick_name: '',
                pay_type: '',
                goods_name: '',
                open: false,
                logo: '',
                goods_num: '',
                receive_tel: '',
                price: '',
                order_num: '',
                time: '',
                note: ''
            },

            oindex: 0
        };
    },
    onLoad: function (t) {
        var that = this;
        var a = uni.getStorageSync('sjdsjid');
        console.log(a, t);
        var s = util.formatTime(new Date()).substring(0, 10).replace(/\//g, '-');
        console.log(s.toString());
        this.setData({
            start: s,
            timestart: s,
            timeend: s
        });
        uni.setNavigationBarTitle({
            title: '拼团订单'
        });
        this.reLoad();
        app.globalData.setNavigationBarColor(this);
        app.globalData.sjdappPageOnLoad(this);
        app.globalData.util.request({
            url: 'entry/wxapp/system',
            cachetime: '0',
            success: function (t) {
                console.log(t.data);
                uni.setStorageSync('system', t.data);
                that.setData({
                    xtxx: t.data
                });
            }
        });
    },
    onReachBottom: function () {
        console.log('上拉加载', this.pagenum);
        if (!this.mygd && this.jzgd) {
            this.setData({
                jzgd: false
            });
            this.reLoad();
        }
    },
    methods: {
        hidemask: function () {
            this.setData({
                selecttype: false,
                selectdate: false
            });
        },

        choseinfo: function () {
            this.setData({
                selectinfo: !this.selectinfo,
                selecttype: false
            });
        },

        qginfoinput: function (t) {
            console.log(t.detail.value);
            this.setData({
                searchinfo: t.detail.value
            });
        },

        search: function () {
            var t = this.searchinfo;
            console.log(t);
            if (t) {
                this.setData({
                    typename: this.datetype[0],
                    state: '',
                    pagenum: 1,
                    order_list: [],
                    storelist: [],
                    mygd: false,
                    jzgd: true,
                    selectinfo: false
                });
                this.reLoad();
            } else {
                uni.showModal({
                    title: '提示',
                    content: '请输入查找内容'
                });
            }
        },

        chosetype: function () {
            this.setData({
                selecttype: !this.selecttype,
                selectdate: false,
                selectinfo: false
            });
        },

        xztype: function (t) {
            var e = t.currentTarget.dataset.index;
            console.log(e);
            this.setData({
                typename: this.datetype[e],
                selecttype: false,
                searchinfo: '',
                state: e,
                start_time: '',
                end_time: '',
                pagenum: 1,
                order_list: [],
                storelist: [],
                mygd: false,
                jzgd: true,
                selectedindex: 0,
                status: 1
            });
            this.reLoad();
        },

        bindTimeChange: function (t) {
            console.log('picker 发生选择改变，携带值为', t.detail.value);
            this.setData({
                timestart: t.detail.value
            });
        },

        bindTimeChange1: function (t) {
            console.log('picker  发生选择改变，携带值为', t.detail.value);
            this.setData({
                timeend: t.detail.value
            });
        },

        find: function () {
            var t = this.timestart;
            var e = this.timeend;
            console.log(util.validTime(t, e));
            if (util.validTime(t, e)) {
                this.setData({
                    typename: this.datetype[0],
                    time: '',
                    pagenum: 1,
                    order_list: [],
                    storelist: [],
                    mygd: false,
                    jzgd: true,
                    selectedindex: 0,
                    status: 1,
                    start_time: t,
                    end_time: e,
                    selectdate: false
                });
                this.reLoad();
            } else {
                uni.showModal({
                    title: '提示',
                    content: '请选择正确的日期范围'
                });
            }
        },

        repeat: function () {
            var t = this.start;
            console.log(t);
            this.setData({
                typename: this.datetype[0],
                time: '',
                pagenum: 1,
                order_list: [],
                storelist: [],
                mygd: false,
                jzgd: true,
                selectedindex: 0,
                status: 1,
                timestart: t,
                timeend: t,
                start_time: '',
                end_time: '',
                selectdate: false
            });
            this.reLoad();
        },

        chosedate: function () {
            this.setData({
                selectdate: !this.selectdate,
                selecttype: false
            });
        },

        maketel: function (t) {
            var e = t.currentTarget.dataset.tel;
            uni.makePhoneCall({
                phoneNumber: e
            });
        },

        location: function (t) {
            var e = t.currentTarget.dataset.lat;
            var a = t.currentTarget.dataset.lng;
            var s = t.currentTarget.dataset.address;
            console.log(e, a);
            uni.openLocation({
                latitude: parseFloat(e),
                longitude: parseFloat(a),
                address: s,
                name: '位置'
            });
        },

        selectednavbar: function (t) {
            console.log(t);
            this.setData({
                pagenum: 1,
                order_list: [],
                storelist: [],
                mygd: false,
                jzgd: true,
                selectedindex: t.currentTarget.dataset.index,
                status: Number(t.currentTarget.dataset.index) + 1
            });
            this.reLoad();
        },

        doreload: function (t) {
            console.log(t);
            this.setData({
                pagenum: 1,
                order_list: [],
                storelist: [],
                mygd: false,
                jzgd: true,
                selectedindex: t - 1,
                status: t
            });
            this.reLoad();
        },

        kindToggle: function (t) {
            var e = t.currentTarget.id;
            var a = this.order_list;
            console.log(e);
            for (var s = 0, i = a.length; s < i; ++s) {
                a[s].open = s == e && !a[s].open;
            }
            this.setData({
                order_list: a
            });
        },

        reLoad: function () {
            var that = this;
            var t = this.status || 1;
            var e = this.state;
            var a = this.searchinfo || '';
            var i = uni.getStorageSync('sjdsjid');
            var n = this.pagenum;
            console.log(t, e, i, n, a);
            app.globalData.util.request({
                url: 'entry/wxapp/StorePtOrder',
                cachetime: '0',
                data: {
                    state: e,
                    keywords: a,
                    store_id: i,
                    page: n,
                    pagesize: 10
                },
                success: function (t) {
                    console.log('分页返回的列表数据', t.data);
                    for (var e = 0; e < t.data.length; e++) {
                        t.data[e].time = util.ormatDate(t.data[e].time);
                        t.data[e].xf_time = util.ormatDate(t.data[e].xf_time);
                    }
                    if (t.data.length < 10) {
                        that.setData({
                            mygd: true,
                            jzgd: true
                        });
                    } else {
                        that.setData({
                            jzgd: true,
                            pagenum: that.pagenum + 1
                        });
                    }
                    var a = that.storelist;
                    a = (function (t) {
                        for (var e = [], a = 0; a < t.length; a++) {
                            if (-1 == e.indexOf(t[a])) {
                                e.push(t[a]);
                            }
                        }
                        return e;
                    })((a = a.concat(t.data)));
                    that.setData({
                        order_list: a,
                        storelist: a
                    });
                    console.log(a);
                }
            });
        },

        smhx: function (t) {
            var a = uni.getStorageSync('sjdsjid');
            uni.scanCode({
                success: function (t) {
                    console.log(t);
                    var e = '/' + t.path;
                    uni.navigateTo({
                        url: e + '&storeid=' + a
                    });
                },
                fail: function (t) {
                    console.log('扫码fail');
                }
            });
        }
    }
};
</script>
<style>
@import './ptdd.css';
</style>
